<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>provide 以及inject 源码分析</title>
    <script src="../node_modules/vue/dist/vue.global.js"></script>
  </head>
  <body>
    <div id="app"></div>

    <script>
      const { reactive, provide, inject, render, h } = Vue

      const MyComponent = {
        setup() {
          debugger
          const personInfo = inject('personInfo')
          return () => h('div', { color: 'red' }, `姓名${personInfo.name} -- 年龄${personInfo.age}`)
        }
      }

      const VueComponent = {
        setup() {
          const state = reactive({ name: 'lihh', age: 20 })

          debugger
          provide('personInfo', state)
          return () => h('div', {}, h(MyComponent))
        }
      }

      render(h(VueComponent), document.getElementById('app'))
    </script>
  </body>
</html>
